﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Configuration;

namespace LINQtoLDAPDemo_Model
{
    public class UserMapping : LinqToLdap.Mapping.ClassMap<User>
    {
        // Manual mapping: http://hattercoding.blogspot.com/2011/02/linq-to-ldap-how-does-it-work-part-2.html
        //public UserMapping()
        //{
        //    NamingContext(string.Format("CN=Users,{0}", ConfigurationSettings.AppSettings["ldapPartition"]));
        //    ObjectCategory("user");

        //    Map(e => e.EmployeeID);
        //    Map(e => e.LastName).Named("sn");
        //    Map(e => e.FirstName).Named("givenName");
        //    Map(e => e.Notes).Named("comment");
        //    Map(e => e.HomePhone);
        //    Map(e => e.Title);
        //    Map(e => e.TitleOfCourtesy).Named("personalTitle");
        //    Map(e => e.DisplayName);

        //    //Map(e => e.ReportsTo).Named("manager");            
        //    //Map(e => e.CN); // throws off Update command when adding management DNs
        //    DistinguishedName(e => e.DistinguishedName);
        //    Map(e => e.Manager);
        //}

        public override LinqToLdap.Mapping.IClassMap PerformMapping(string namingContext = null, string objectCategory = null, bool includeObjectCategory = true, IEnumerable<string> objectClasses = null, bool includeObjectClasses = true)
        {
            NamingContext(string.Format("CN=Users,{0}", ConfigurationSettings.AppSettings["ldapPartition"]));
            ObjectCategory("user");

            Map(e => e.EmployeeID);
            Map(e => e.LastName).Named("sn");
            Map(e => e.FirstName).Named("givenName");
            Map(e => e.Notes).Named("comment");
            Map(e => e.HomePhone);
            Map(e => e.Title);
            Map(e => e.TitleOfCourtesy).Named("personalTitle");
            Map(e => e.DisplayName);

            DistinguishedName(e => e.DistinguishedName);
            Map(e => e.Manager);

            return this;
        }
    }
}
